import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import os
import glob
import re
from cycler import cycler
import fiona
import geopandas as gp
import matplotlib.pyplot as plt
import pandas as pd
from matplotlib import collections
import matplotlib.pyplot as plt
from shapely.geometry import LineString, Point, Polygon
%matplotlib inline
sns.color_palette()
sns.set_style("white", {"xtick.direction": "in","ytick.direction": "in"})
sns.color_palette("Set2")
plt.rcParams['xtick.bottom'] = True
plt.rcParams['ytick.left'] = True
The files I am going to load are the ones showed in the table below. This is to know which file correspond to what. I have not added the dates in the file name since they are autogenerated and it is a sanity check for me, but in reality the dates (numbers in front of the file name scenario) don't matter.

cwd = os.getcwd()
facility_label = ['Manufacturing', 'Recycling', 'Manufacturing_cap', 'Recycling_cap']
location_label = ['NAICS', '40209']
factor_label_rec = ['05', '1', '2', '5', '10']
factor_label_man = ['0001','05', '1', '2'] # 0 is 0,5
files_list = []
for fac in facility_label:
for loc in location_label:
if fac.startswith('Manufacturing'):
for fac_man in factor_label_man:
files_list.append(fac+'_'+loc+'_'+fac_man)
else:
for fac_rec in factor_label_rec:
files_list.append(fac+'_'+loc+'_'+fac_rec)
recycling_files = [x for x in files_list if x.startswith('Recycling')]
recycling_files_cap = [x for x in recycling_files if "cap" in x]
recycling_files_cost = [x for x in recycling_files if "cap" not in x]
manufacturing_files = [x for x in files_list if x.startswith('Manufacturing')]
manufacturing_files_cap = [x for x in manufacturing_files if "cap" in x]
manufacturing_files_cost = [x for x in manufacturing_files if "cap" not in x]
year_list = list(range(2025, 2051, 1))
number_year = list(range(1, 27, 1))
years_dict = dict(zip(number_year,year_list))
for files in recycling_files_cost:
testfile_path = glob.glob(os.path.join(cwd, "scenarios_after_update", files, 'plants.csv'))[0]
globals()['%s_plants' % (files)] = pd.read_csv(testfile_path)
globals()['%s_plants' % (files)] = globals()['%s_plants' % (files)].replace({"year": years_dict})
print('{}: {} locations'.format(files, len(globals()['%s_plants' % (files)]['location name'].unique())))
Recycling_NAICS_05: 81 locations Recycling_NAICS_1: 81 locations Recycling_NAICS_2: 81 locations Recycling_NAICS_5: 81 locations Recycling_NAICS_10: 81 locations Recycling_40209_05: 81 locations Recycling_40209_1: 81 locations Recycling_40209_2: 81 locations Recycling_40209_5: 81 locations Recycling_40209_10: 81 locations
Some of the manufacturing files have no solution, so we remove them:
for files in manufacturing_files_cost:
testfile_path = glob.glob(os.path.join(cwd, "scenarios_after_update", files, 'plants.csv'))[0]
globals()['%s_plants' % (files)] = pd.read_csv(testfile_path)
globals()['%s_plants' % (files)] = globals()['%s_plants' % (files)].replace({"year": years_dict})
print('{}: {} locations'.format(files, len(globals()['%s_plants' % (files)]['location name'].unique())))
Manufacturing_NAICS_0001: 187 locations Manufacturing_NAICS_05: 166 locations Manufacturing_NAICS_1: 166 locations Manufacturing_NAICS_2: 166 locations Manufacturing_40209_0001: 177 locations Manufacturing_40209_05: 166 locations Manufacturing_40209_1: 166 locations Manufacturing_40209_2: 166 locations
for files in recycling_files_cap:
testfile_path = glob.glob(os.path.join(cwd, "scenarios_after_update", files, 'plants.csv'))[0]
globals()['%s_plants' % (files)] = pd.read_csv(testfile_path)
globals()['%s_plants' % (files)] = globals()['%s_plants' % (files)].replace({"year": years_dict})
print('{}: {} locations'.format(files, len(globals()['%s_plants' % (files)]['location name'].unique())))
Recycling_cap_NAICS_05: 161 locations Recycling_cap_NAICS_1: 81 locations Recycling_cap_NAICS_2: 41 locations Recycling_cap_NAICS_5: 17 locations Recycling_cap_NAICS_10: 9 locations Recycling_cap_40209_05: 161 locations Recycling_cap_40209_1: 81 locations Recycling_cap_40209_2: 41 locations Recycling_cap_40209_5: 17 locations Recycling_cap_40209_10: 9 locations
manufacturing_files_cap.remove('Manufacturing_cap_NAICS_0001')
manufacturing_files_cap.remove('Manufacturing_cap_NAICS_05')
manufacturing_files_cap.remove('Manufacturing_cap_40209_0001')
manufacturing_files_cap.remove('Manufacturing_cap_40209_05')
for files in manufacturing_files_cap:
testfile_path = glob.glob(os.path.join(cwd, "scenarios_after_update", files, 'plants.csv'))[0]
globals()['%s_plants' % (files)] = pd.read_csv(testfile_path)
globals()['%s_plants' % (files)] = globals()['%s_plants' % (files)].replace({"year": years_dict})
print('{}: {} locations'.format(files, len(globals()['%s_plants' % (files)]['location name'].unique())))
Manufacturing_cap_NAICS_1: 166 locations Manufacturing_cap_NAICS_2: 83 locations Manufacturing_cap_40209_1: 166 locations Manufacturing_cap_40209_2: 83 locations
rec_cap_locs_data = [['Capacity', 'Recycling', 'NAICS', 0.5, 161],
['Capacity', 'Recycling','NAICS',1, 81],
['Capacity', 'Recycling','NAICS',2, 41],
['Capacity', 'Recycling','NAICS',5, 17],
['Capacity', 'Recycling','NAICS',10, 9],
['Capacity', 'Recycling', '40209', 0.5, 161],
['Capacity', 'Recycling','40209',1, 81],
['Capacity', 'Recycling','40209',2, 41],
['Capacity', 'Recycling','40209',5, 17],
['Capacity', 'Recycling','40209',10, 9],
['Cost', 'Recycling', 'NAICS',0.5, 81],
['Cost', 'Recycling','NAICS',1, 81],
['Cost', 'Recycling','NAICS',2, 81],
['Cost', 'Recycling','NAICS',5, 81],
['Cost', 'Recycling','NAICS',10, 81],
['Cost', 'Recycling', '40209',0.5, 81],
['Cost', 'Recycling','40209',1, 81],
['Cost', 'Recycling','40209',2, 81],
['Cost', 'Recycling','40209',5, 81],
['Cost', 'Recycling','40209',10, 81],
['Capacity', 'Manufacturing', 'NAICS',1, 166],
['Capacity', 'Manufacturing', 'NAICS',2, 83],
['Capacity', 'Manufacturing', '40209', 1, 166],
['Capacity', 'Manufacturing', '40209', 2, 83],
['Cost', 'Manufacturing', 'NAICS',0.001, 187],
['Cost', 'Manufacturing', 'NAICS',0.5, 166],
['Cost', 'Manufacturing', 'NAICS',1, 166],
['Cost', 'Manufacturing', 'NAICS',2, 166],
['Cost', 'Manufacturing', '40209',0.001, 177],
['Cost', 'Manufacturing', '40209',0.5, 166],
['Cost', 'Manufacturing', '40209',1, 166],
['Cost', 'Manufacturing', '40209',2, 166]]
rec_cap_locs_data_df = pd.DataFrame(rec_cap_locs_data, columns=['Analysis', 'Facility', 'Location group','Factor', 'Selected locations'])
rec_cap_locs_data_df.loc[rec_cap_locs_data_df['Facility'] == 'Recycling' ]
| Analysis | Facility | Location group | Factor | Selected locations | |
|---|---|---|---|---|---|
| 0 | Capacity | Recycling | NAICS | 0.5 | 161 |
| 1 | Capacity | Recycling | NAICS | 1.0 | 81 |
| 2 | Capacity | Recycling | NAICS | 2.0 | 41 |
| 3 | Capacity | Recycling | NAICS | 5.0 | 17 |
| 4 | Capacity | Recycling | NAICS | 10.0 | 9 |
| 5 | Capacity | Recycling | 40209 | 0.5 | 161 |
| 6 | Capacity | Recycling | 40209 | 1.0 | 81 |
| 7 | Capacity | Recycling | 40209 | 2.0 | 41 |
| 8 | Capacity | Recycling | 40209 | 5.0 | 17 |
| 9 | Capacity | Recycling | 40209 | 10.0 | 9 |
| 10 | Cost | Recycling | NAICS | 0.5 | 81 |
| 11 | Cost | Recycling | NAICS | 1.0 | 81 |
| 12 | Cost | Recycling | NAICS | 2.0 | 81 |
| 13 | Cost | Recycling | NAICS | 5.0 | 81 |
| 14 | Cost | Recycling | NAICS | 10.0 | 81 |
| 15 | Cost | Recycling | 40209 | 0.5 | 81 |
| 16 | Cost | Recycling | 40209 | 1.0 | 81 |
| 17 | Cost | Recycling | 40209 | 2.0 | 81 |
| 18 | Cost | Recycling | 40209 | 5.0 | 81 |
| 19 | Cost | Recycling | 40209 | 10.0 | 81 |
figure = sns.lineplot(x='Factor', y='Selected locations', data=rec_cap_locs_data_df.loc[rec_cap_locs_data_df['Facility'] == 'Recycling'], marker='o', hue='Analysis', style="Analysis", )
figure.legend(frameon=False)
figure.set(title='Recycling')
[Text(0.5, 1.0, 'Recycling')]
figure = sns.lineplot(x='Factor', y='Selected locations', data=rec_cap_locs_data_df.loc[rec_cap_locs_data_df['Facility'] == 'Manufacturing'], marker='o', hue='Analysis', style="Analysis", )
figure.legend(frameon=False)
figure.set(title='Manufacturing')
[Text(0.5, 1.0, 'Manufacturing')]
for files in recycling_files_cap:
# Initialize a grid of plots with an Axes for each walk
grid = sns.FacetGrid(globals()['%s_plants' % (files)], col="location name",
col_wrap=9, height=1.5)
# Draw a horizontal line to show the starting point
grid.refline(y=0, linestyle=":")
grid.map(plt.plot, "year", "utilization factor (%)", color="powderblue")
grid.map(plt.fill_between, 'year', 'utilization factor (%)',color= "powderblue", alpha= 0.2)
# Adjust the tick positions, labels and
#sns.set(font_scale=0.1)
grid.set_titles(row_template = '{row_name}', col_template = '{col_name}', size=5)
grid.fig.tight_layout(w_pad=1)
grid.fig.subplots_adjust(top=0.9)
grid.fig.suptitle(f"{files}")
plt.savefig(os.path.join(cwd, f"grid_after_update/grid_{files}_cap_uf.png"), transparent=True);
for files in recycling_files_cap:
# Initialize a grid of plots with an Axes for each walk
grid = sns.FacetGrid(globals()['%s_plants' % (files)], col="location name",
col_wrap=9, height=1.5)
# Draw a horizontal line to show the starting point
grid.refline(y=0, linestyle=":")
grid.map(plt.plot, "year", "total cost ($)", color="powderblue")
grid.map(plt.fill_between, 'year', 'total cost ($)',color= "powderblue", alpha= 0.2)
# Adjust the tick positions, labels and
#sns.set(font_scale=0.1)
grid.set_titles(row_template = '{row_name}', col_template = '{col_name}', size=5)
grid.fig.tight_layout(w_pad=1)
grid.fig.subplots_adjust(top=0.9)
grid.fig.suptitle(f"{files}")
plt.savefig(os.path.join(cwd, f"grid_after_update/grid_{files}_cap_totcost.png"), transparent=True);
for files in recycling_files_cost:
# Initialize a grid of plots with an Axes for each walk
# Initialize a grid of plots with an Axes for each walk
grid = sns.FacetGrid(globals()['%s_plants' % (files)], col="location name",
col_wrap=9, height=1.5)
# Draw a horizontal line to show the starting point
grid.refline(y=0, linestyle=":")
grid.map(plt.plot, "year", "utilization factor (%)", color="powderblue")
grid.map(plt.fill_between, "year", 'utilization factor (%)',color= "powderblue", alpha= 0.2)
# Adjust the tick positions, labels and
#sns.set(font_scale=0.1)
grid.set_titles(row_template = '{row_name}', col_template = '{col_name}', size=5)
grid.fig.tight_layout(w_pad=1)
grid.fig.subplots_adjust(top=0.9)
grid.fig.suptitle(f"{files}")
plt.savefig(os.path.join(cwd, f"grid_after_update/grid_{files}_cost_uf.png"), transparent=True);
for files in recycling_files_cost:
# Initialize a grid of plots with an Axes for each walk
grid = sns.FacetGrid(globals()['%s_plants' % (files)], col="location name",
col_wrap=9, height=1.5)
# Draw a horizontal line to show the starting point
grid.refline(y=0, linestyle=":")
grid.map(plt.plot, "year", "total cost ($)", color="powderblue")
grid.map(plt.fill_between, 'year', 'total cost ($)',color= "powderblue", alpha= 0.2)
# Adjust the tick positions, labels and
#sns.set(font_scale=0.1)
grid.set_titles(row_template = '{row_name}', col_template = '{col_name}', size=5)
grid.fig.tight_layout(w_pad=1)
grid.fig.subplots_adjust(top=0.9)
grid.fig.suptitle(f"{files}")
plt.savefig(os.path.join(cwd, f"grid_after_update/grid_{files}_cost_totcost.png"), transparent=True);
for files in manufacturing_files_cap:
# Initialize a grid of plots with an Axes for each walk
grid = sns.FacetGrid(globals()['%s_plants' % (files)], col="location name",
col_wrap=9, height=1.5)
# Draw a horizontal line to show the starting point
grid.refline(y=0, linestyle=":")
grid.map(plt.plot, "year", "utilization factor (%)", color='gold')
grid.map(plt.fill_between, 'year', 'utilization factor (%)',color= "gold", alpha= 0.2)
# Adjust the tick positions, labels and
#sns.set(font_scale=0.1)
grid.set_titles(row_template = '{row_name}', col_template = '{col_name}', size=5)
grid.fig.tight_layout(w_pad=1)
grid.fig.subplots_adjust(top=0.9)
grid.fig.suptitle(f"{files}")
plt.savefig(os.path.join(cwd, f"grid_after_update/grid_{files}_cap_uf.png"), transparent=True);
for files in manufacturing_files_cap:
# Initialize a grid of plots with an Axes for each walk
grid = sns.FacetGrid(globals()['%s_plants' % (files)], col="location name",
col_wrap=9, height=1.5)
# Draw a horizontal line to show the starting point
grid.refline(y=0, linestyle=":")
grid.map(plt.plot, "year", "total cost ($)", color='gold')
grid.map(plt.fill_between, 'year', 'total cost ($)',color= "gold", alpha= 0.2)
# Adjust the tick positions, labels and
#sns.set(font_scale=0.1)
grid.set_titles(row_template = '{row_name}', col_template = '{col_name}', size=5)
grid.fig.tight_layout(w_pad=1)
grid.fig.subplots_adjust(top=0.9)
grid.fig.suptitle(f"{files}")
plt.savefig(os.path.join(cwd, f"grid_after_update/grid_{files}_cap_totcost.png"), transparent=True);
for files in manufacturing_files_cost:
# Initialize a grid of plots with an Axes for each walk
# Initialize a grid of plots with an Axes for each walk
grid = sns.FacetGrid(globals()['%s_plants' % (files)], col="location name",
col_wrap=9, height=1.5)
# Draw a horizontal line to show the starting point
grid.refline(y=0, linestyle=":")
grid.map(plt.plot, "year", "utilization factor (%)", color='gold')
grid.map(plt.fill_between, 'year', 'utilization factor (%)',color= "gold", alpha= 0.2)
# Adjust the tick positions, labels and
#sns.set(font_scale=0.1)
grid.set_titles(row_template = '{row_name}', col_template = '{col_name}', size=5)
grid.fig.tight_layout(w_pad=1)
grid.fig.subplots_adjust(top=0.9)
grid.fig.suptitle(f"{files}")
plt.savefig(os.path.join(cwd, f"grid_after_update/grid_{files}_cost_uf.png"), transparent=True);
for files in manufacturing_files_cost:
# Initialize a grid of plots with an Axes for each walk
grid = sns.FacetGrid(globals()['%s_plants' % (files)], col="location name",
col_wrap=9, height=1.5)
# Draw a horizontal line to show the starting point
grid.refline(y=0, linestyle=":")
grid.map(plt.plot, "year", "total cost ($)", color='gold')
grid.map(plt.fill_between, 'year', 'total cost ($)',color= "gold", alpha= 0.2)
# Adjust the tick positions, labels and
#sns.set(font_scale=0.1)
grid.set_titles(row_template = '{row_name}', col_template = '{col_name}', size=5)
grid.fig.tight_layout(w_pad=1)
grid.fig.subplots_adjust(top=0.9)
grid.fig.suptitle(f"{files}")
plt.savefig(os.path.join(cwd, f"grid_after_update/grid_{files}_cost_totcost.png"), transparent=True);
USA map source2.
import fiona
import geopandas as gp
import matplotlib.pyplot as plt
import pandas as pd
from matplotlib import collections
import matplotlib.pyplot as plt
from shapely.geometry import LineString, Point, Polygon
%matplotlib inline
for files in recycling_files_cost:
testfile_path = glob.glob(os.path.join(cwd, "scenarios_after_update", files, 'transportation.csv'))[0]
globals()['%s_transportation' % (files)] = pd.read_csv(testfile_path)
globals()['%s_transportation' % (files)] = globals()['%s_transportation' % (files)].replace({"year": years_dict})
for files in recycling_files_cap:
testfile_path = glob.glob(os.path.join(cwd, "scenarios_after_update", files, 'transportation.csv'))[0]
globals()['%s_transportation' % (files)] = pd.read_csv(testfile_path)
globals()['%s_transportation' % (files)] = globals()['%s_transportation' % (files)].replace({"year": years_dict})
for files in manufacturing_files_cost:
testfile_path = glob.glob(os.path.join(cwd, "scenarios_after_update", files, 'transportation.csv'))[0]
globals()['%s_transportation' % (files)] = pd.read_csv(testfile_path)
globals()['%s_transportation' % (files)] = globals()['%s_transportation' % (files)].replace({"year": years_dict})
for files in manufacturing_files_cap:
testfile_path = glob.glob(os.path.join(cwd, "scenarios_after_update", files, 'transportation.csv'))[0]
globals()['%s_transportation' % (files)] = pd.read_csv(testfile_path)
globals()['%s_transportation' % (files)] = globals()['%s_transportation' % (files)].replace({"year": years_dict})
for files in recycling_files_cost:
# Plot base map
world = gp.read_file(os.path.join(f'resources','USA_States_(Generalized)', 'USA_States_Generalized.shp'))
world = world.to_crs("EPSG:4326")
ax = world.plot(color="0.8", edgecolor="1", figsize=(14, 7))
ax.set_ylim([23, 50])
ax.set_xlim([-128, -65])
plt.axis('off')
ax.set(title=f'{files}')
# Draw transportation lines
data = globals()['%s_transportation' % (files)]
lines = [
[
(
row["source longitude (deg)"],
row["source latitude (deg)"],
),
(
row["destination longitude (deg)"],
row["destination latitude (deg)"],
),
]
for (index, row) in data.iterrows()
]
ax.add_collection(
collections.LineCollection(
lines,
linewidths=0.005,
zorder=1,
alpha=1,
color="powderblue",
)
)
# Draw source points
points = gp.points_from_xy(
data["source longitude (deg)"],
data["source latitude (deg)"],
)
gp.GeoDataFrame(data, geometry=points).plot(ax=ax, color="0.6", markersize=1)
# Draw destination points
points = gp.points_from_xy(
data["destination longitude (deg)"],
data["destination latitude (deg)"],
)
gp.GeoDataFrame(data, geometry=points).plot(ax=ax, markersize=50, color="palevioletred", edgecolor='white')
plt.savefig(os.path.join("maps_after_update",f"map_{files}_cost.png"), transparent=True, dpi=300);
plt.savefig(os.path.join("maps_after_update",f"map_{files}_cost.pdf"), dpi=300);
for files in recycling_files_cap:
# Plot base map
world = gp.read_file(os.path.join(f'resources','USA_States_(Generalized)', 'USA_States_Generalized.shp'))
world = world.to_crs("EPSG:4326")
ax = world.plot(color="0.8", edgecolor="1", figsize=(14, 7))
ax.set_ylim([23, 50])
ax.set_xlim([-128, -65])
plt.axis('off')
ax.set(title=f'{files}')
# Draw transportation lines
data = globals()['%s_transportation' % (files)]
lines = [
[
(
row["source longitude (deg)"],
row["source latitude (deg)"],
),
(
row["destination longitude (deg)"],
row["destination latitude (deg)"],
),
]
for (index, row) in data.iterrows()
]
ax.add_collection(
collections.LineCollection(
lines,
linewidths=0.005,
zorder=1,
alpha=1,
color="powderblue",
)
)
# Draw source points
points = gp.points_from_xy(
data["source longitude (deg)"],
data["source latitude (deg)"],
)
gp.GeoDataFrame(data, geometry=points).plot(ax=ax, color="0.6", markersize=1)
# Draw destination points
points = gp.points_from_xy(
data["destination longitude (deg)"],
data["destination latitude (deg)"],
)
gp.GeoDataFrame(data, geometry=points).plot(ax=ax, markersize=50, color="palevioletred", edgecolor='white')
plt.savefig(os.path.join("maps_after_update",f"map_{files}_cap.png"), transparent=True, dpi=300);
plt.savefig(os.path.join("maps_after_update",f"map_{files}_cap.pdf"), dpi=300);
for files in manufacturing_files_cost:
# Plot base map
world = gp.read_file(os.path.join(f'resources','USA_States_(Generalized)', 'USA_States_Generalized.shp'))
world = world.to_crs("EPSG:4326")
ax = world.plot(color="gold", edgecolor="1", figsize=(14, 7))
ax.set_ylim([23, 50])
ax.set_xlim([-128, -65])
plt.axis('off')
ax.set(title=f'{files}')
# Draw transportation lines
data = globals()['%s_transportation' % (files)]
lines = [
[
(
row["source longitude (deg)"],
row["source latitude (deg)"],
),
(
row["destination longitude (deg)"],
row["destination latitude (deg)"],
),
]
for (index, row) in data.iterrows()
]
ax.add_collection(
collections.LineCollection(
lines,
linewidths=0.005,
zorder=1,
alpha=0.3,
color="0.8",
)
)
# Draw source points
points = gp.points_from_xy(
data["source longitude (deg)"],
data["source latitude (deg)"],
)
gp.GeoDataFrame(data, geometry=points).plot(ax=ax, color="0.6", markersize=1)
# Draw destination points
points = gp.points_from_xy(
data["destination longitude (deg)"],
data["destination latitude (deg)"],
)
gp.GeoDataFrame(data, geometry=points).plot(ax=ax, markersize=50, color="mediumpurple", edgecolor='white')
plt.savefig(os.path.join("maps_after_update",f"map_{files}_cost.png"), transparent=True, dpi=300);
plt.savefig(os.path.join("maps_after_update",f"map_{files}_cost.pdf"), dpi=300);
for files in manufacturing_files_cap:
# Plot base map
world = gp.read_file(os.path.join(f'resources','USA_States_(Generalized)', 'USA_States_Generalized.shp'))
world = world.to_crs("EPSG:4326")
ax = world.plot(color="gold", edgecolor="1", figsize=(14, 7))
ax.set_ylim([23, 50])
ax.set_xlim([-128, -65])
plt.axis('off')
ax.set(title=f'{files}')
# Draw transportation lines
data = globals()['%s_transportation' % (files)]
lines = [
[
(
row["source longitude (deg)"],
row["source latitude (deg)"],
),
(
row["destination longitude (deg)"],
row["destination latitude (deg)"],
),
]
for (index, row) in data.iterrows()
]
ax.add_collection(
collections.LineCollection(
lines,
linewidths=0.005,
zorder=1,
alpha=0.3,
color="0.8",
)
)
# Draw source points
points = gp.points_from_xy(
data["source longitude (deg)"],
data["source latitude (deg)"],
)
gp.GeoDataFrame(data, geometry=points).plot(ax=ax, color="0.6", markersize=1)
# Draw destination points
points = gp.points_from_xy(
data["destination longitude (deg)"],
data["destination latitude (deg)"],
)
gp.GeoDataFrame(data, geometry=points).plot(ax=ax, markersize=50, color="mediumpurple", edgecolor='white')
plt.savefig(os.path.join("maps_after_update",f"map_{files}_cap.png"), transparent=True, dpi=300);
plt.savefig(os.path.join("maps_after_update",f"map_{files}_cap.pdf"), dpi=300);
# Plot base map
world = gp.read_file(os.path.join(f'resources','USA_States_(Generalized)', 'USA_States_Generalized.shp'))
world = world.to_crs("EPSG:4326")
ax = world.plot(color="gold", edgecolor="1", figsize=(14, 7))
ax.set_ylim([23, 50])
ax.set_xlim([-128, -65])
plt.axis('off')
ax.set(title=f'Recycling_40209_1_transportation')
# Draw transportation lines
data = Recycling_40209_1_transportation
lines = [
[
(
row["source longitude (deg)"],
row["source latitude (deg)"],
),
(
row["destination longitude (deg)"],
row["destination latitude (deg)"],
),
]
for (index, row) in data.iterrows()
]
ax.add_collection(
collections.LineCollection(
lines,
linewidths=0.005,
zorder=1,
alpha=0.3,
color="0.8",
)
)
# Draw source points
points = gp.points_from_xy(
data["source longitude (deg)"],
data["source latitude (deg)"],
)
gp.GeoDataFrame(data, geometry=points).plot(ax=ax, color="0.6", markersize=1)
# Draw destination points
points = gp.points_from_xy(
data["destination longitude (deg)"],
data["destination latitude (deg)"],
)
gp.GeoDataFrame(data, geometry=points).plot(ax=ax, markersize=50, color="mediumpurple", edgecolor='white')
<AxesSubplot:title={'center':'Recycling_40209_1_transportation'}>
world = gp.read_file(os.path.join(f'resources','USA_States_(Generalized)', 'USA_States_Generalized.shp'))
world = world.to_crs("EPSG:4326")
ax = world.plot(color="gold", edgecolor="1")
ax.set_ylim([23, 50])
ax.set_xlim([-128, -65])
plt.axis('off')
(-128.0, -65.0, 23.0, 50.0)
Recycling_40209_1_plants.keys()
Index(['plant type', 'location name', 'year', 'latitude (deg)',
'longitude (deg)', 'capacity (tonne)', 'amount processed (tonne)',
'amount received (tonne)', 'amount in storage (tonne)',
'utilization factor (%)', 'energy (GJ)', 'opening cost ($)',
'expansion cost ($)', 'fixed operating cost ($)',
'variable operating cost ($)', 'storage cost ($)', 'total cost ($)'],
dtype='object')
grid = sns.FacetGrid(Recycling_40209_1_plants, col="location name",
col_wrap=9, height=1.5)
# Draw a horizontal line to show the starting point
grid.refline(y=0, linestyle=":")
grid.map(plt.plot, "year", 'total cost ($)', color="powderblue")
grid.map(plt.fill_between, 'year', 'total cost ($)',color= "powderblue", alpha= 0.2)
# Adjust the tick positions, labels and
#sns.set(font_scale=0.1)
grid.set_titles(row_template = '{row_name}', col_template = '{col_name}', size=5)
grid.fig.tight_layout(w_pad=1)
grid.fig.subplots_adjust(top=0.9)
grid.fig.suptitle(f"Title")
#plt.savefig(os.path.join(cwd, f"grid_after_update/grid_{files}_cap_uf.png"), transparent=True);
Text(0.5, 0.98, 'Title')
def intersection(lst1, lst2):
lst3 = [value for value in lst1 if value in lst2]
return lst3
print('40209 overlap x0.5 cost:', len(intersection(Recycling_40209_05_plants['location name'].unique(),
Manufacturing_40209_05_plants['location name'].unique())))
print('40209 overlap x1 cost:', len(intersection(Recycling_40209_1_plants['location name'].unique(),
Manufacturing_40209_1_plants['location name'].unique())))
print('40209 overlap x2 cost:', len(intersection(Recycling_40209_2_plants['location name'].unique(),
Manufacturing_40209_2_plants['location name'].unique())))
print('NAICS overlap x0.5 cost:', len(intersection(Recycling_NAICS_05_plants['location name'].unique(),
Manufacturing_NAICS_05_plants['location name'].unique())))
print('NAICS overlap x1 cost:', len(intersection(Recycling_NAICS_1_plants['location name'].unique(),
Manufacturing_NAICS_1_plants['location name'].unique())))
print('NAICS overlap x2 cost:', len(intersection(Recycling_NAICS_2_plants['location name'].unique(),
Manufacturing_NAICS_2_plants['location name'].unique())))
print('40209 overlap x1 capacity:', len(intersection(Recycling_cap_40209_1_plants['location name'].unique(),
Manufacturing_cap_40209_1_plants['location name'].unique())))
print('40209 overlap x2 capacity:', len(intersection(Recycling_cap_40209_2_plants['location name'].unique(),
Manufacturing_cap_40209_2_plants['location name'].unique())))
print('NAICS overlap x1 capacity:', len(intersection(Recycling_cap_NAICS_1_plants['location name'].unique(),
Manufacturing_cap_NAICS_1_plants['location name'].unique()))),
print('NAICS overlap x2 capacity:', len(intersection(Recycling_cap_NAICS_2_plants['location name'].unique(),
Manufacturing_cap_NAICS_2_plants['location name'].unique())))
40209 overlap x0.5 cost: 72 40209 overlap x1 cost: 79 40209 overlap x2 cost: 81 NAICS overlap x0.5 cost: 79 NAICS overlap x1 cost: 81 NAICS overlap x2 cost: 81 40209 overlap x1 capacity: 79 40209 overlap x2 capacity: 37 NAICS overlap x1 capacity: 81 NAICS overlap x2 capacity: 37
Recycling_40209_1_plants.keys()
Index(['plant type', 'location name', 'year', 'latitude (deg)',
'longitude (deg)', 'capacity (tonne)', 'amount processed (tonne)',
'amount received (tonne)', 'amount in storage (tonne)',
'utilization factor (%)', 'energy (GJ)', 'opening cost ($)',
'expansion cost ($)', 'fixed operating cost ($)',
'variable operating cost ($)', 'storage cost ($)', 'total cost ($)'],
dtype='object')
common_rec_40209 = intersection( # Cost analysis
intersection(
intersection(
intersection(
Recycling_40209_1_plants['location name'].unique(),
Recycling_40209_05_plants['location name'].unique()),
Recycling_40209_2_plants['location name'].unique()),
Recycling_40209_5_plants['location name'].unique()),
Recycling_40209_10_plants['location name'].unique())
len(common_rec_40209)
58
common_rec_cap_40209 = intersection( # Capacity analysis
intersection(
intersection(
intersection(
Recycling_cap_40209_1_plants['location name'].unique(),
Recycling_cap_40209_05_plants['location name'].unique()),
Recycling_cap_40209_2_plants['location name'].unique()),
Recycling_cap_40209_5_plants['location name'].unique()),
Recycling_cap_40209_10_plants['location name'].unique())
len(common_rec_cap_40209)
8
Recycling_cap_40209_05_plants['location name']
0 Glen Lyn, Virginia
1 Glen Lyn, Virginia
2 Glen Lyn, Virginia
3 Glen Lyn, Virginia
4 Glen Lyn, Virginia
...
4181 J C Weadock, Michigan
4182 J C Weadock, Michigan
4183 J C Weadock, Michigan
4184 J C Weadock, Michigan
4185 J C Weadock, Michigan
Name: location name, Length: 4186, dtype: object
common_man_40209 = intersection( # Cost analysis
intersection(
intersection(
Manufacturing_40209_0001_plants['location name'].unique(),
Manufacturing_40209_05_plants['location name'].unique()),
Manufacturing_40209_1_plants['location name'].unique()),
Manufacturing_40209_2_plants['location name'].unique())
len(common_man_40209)
119
common_man_cap_40209 = intersection( # Capacity analysis
Manufacturing_cap_40209_1_plants['location name'].unique(),
Manufacturing_cap_40209_2_plants['location name'].unique())
len(common_man_cap_40209)
83
common_40209 = intersection(
intersection(
intersection(
common_rec_40209, common_rec_cap_40209),
common_man_40209),
common_man_cap_40209)
len(common_40209)
8
common_40209
['San Juan, New Mexico', 'Cholla, Arizona', 'R D Morrow, Mississippi', 'Northeastern, Oklahoma', 'Crystal River, Florida', 'Clinch River, Virginia', 'Potomac River, Virginia', 'Navajo, Arizona']
I choose three locations:
- 'Navajo, Arizona'
- 'Clinch River, Virginia'
- 'R D Morrow, Mississippi'
common_40209_selected = ['Navajo, Arizona', 'Clinch River, Virginia', 'R D Morrow, Mississippi']
plt.rcParams['axes.prop_cycle'] = plt.cycler(color=plt.cm.Set2.colors[:6])
fig, axs = plt.subplots(3, 2, figsize=(10,10),sharex=True)
fig.tight_layout(pad=1.5)
fig.suptitle("40209 Recycling plants - Cost Sensitivity Analysis",fontsize=20)
fig.subplots_adjust(top=0.92)
for files in recycling_files_cost:
if '40209' in files:
state = globals()['%s_plants' % (files)].loc[globals()['%s_plants' % (files)]['location name'] == 'Navajo, Arizona']
regex = re.findall('\w+_\w+_(\d{1,2})', files)[0]
axs[0, 0].plot(state['year'], state['utilization factor (%)'], label = fr'{regex}')
axs[0, 0].fill_between(state['year'], state['utilization factor (%)'], alpha=0.1)
#axs[0].legend(bbox_to_anchor=(1, 1.05), frameon=False)
axs[0, 0].set_title('Navajo, Arizona')
axs[0, 0].margins(x=0, y=0)
# axs[0].xlabel('Year')
# axs[0].ylabel('Utilization factor (%)')
axs[0, 0].set(xlabel=" ", ylabel="Utilization factor (%)")
for files in recycling_files_cost:
if '40209' in files:
state = globals()['%s_plants' % (files)].loc[globals()['%s_plants' % (files)]['location name'] == 'Clinch River, Virginia']
regex = re.findall('\w+_\w+_(\d{1,2})', files)[0]
axs[1, 0].plot(state['year'], state['utilization factor (%)'], label = fr'{regex}')
axs[1, 0].fill_between(state['year'], state['utilization factor (%)'], alpha=0.1)
#axs[1, 0].legend(bbox_to_anchor=(1.1, 0.75), frameon=False)
axs[1, 0].set_title('Clinch River, Virginia')
axs[1, 0].margins(x=0, y=0)
axs[1, 0].set(xlabel=" ", ylabel="Utilization factor (%)")
# for ax in axs.flat:
# ax.set(xlabel='Year', ylabel='Utilization factor (%)')
for files in recycling_files_cost:
if '40209' in files:
state = globals()['%s_plants' % (files)].loc[globals()['%s_plants' % (files)]['location name'] == 'R D Morrow, Mississippi']
regex = re.findall('\w+_\w+_(\d{1,2})', files)[0]
axs[2, 0].plot(state['year'], state['utilization factor (%)'], label = fr'{regex}')
axs[2, 0].fill_between(state['year'], state['utilization factor (%)'], alpha=0.1)
#axs[2].legend(bbox_to_anchor=(1, 1.05), frameon=False)
axs[2, 0].set_title('R D Morrow, Mississippi')
axs[2, 0].margins(x=0, y=0)
axs[2, 0].set(xlabel="Year", ylabel="Utilization factor (%)")
for files in recycling_files_cost:
if '40209' in files:
state = globals()['%s_plants' % (files)].loc[globals()['%s_plants' % (files)]['location name'] == 'Navajo, Arizona']
regex = re.findall('\w+_\w+_(\d{1,2})', files)[0]
axs[0, 1].plot(state['year'], state['total cost ($)'], label = fr'{regex}')
axs[0, 1].fill_between(state['year'], state['total cost ($)'], alpha=0.1)
#axs[0].legend(bbox_to_anchor=(1, 1.05), frameon=False)
axs[0, 1].set_title('Navajo, Arizona')
axs[0, 1].margins(x=0, y=0)
# axs[0].xlabel('Year')
# axs[0].ylabel('Utilization factor (%)')
axs[0, 1].set(xlabel=" ", ylabel="Total cost ($)")
for files in recycling_files_cost:
if '40209' in files:
state = globals()['%s_plants' % (files)].loc[globals()['%s_plants' % (files)]['location name'] == 'Clinch River, Virginia']
regex = re.findall('\w+_\w+_(\d{1,2})', files)[0]
axs[1, 1].plot(state['year'], state['total cost ($)'], label = fr'{regex}')
axs[1, 1].fill_between(state['year'], state['total cost ($)'], alpha=0.1)
axs[1, 1].legend(bbox_to_anchor=(1.2, 0.75), frameon=False)
axs[1, 1].set_title('Clinch River, Virginia')
axs[1, 1].margins(x=0, y=0)
axs[1, 1].set(xlabel=" ", ylabel="Total cost ($)")
# for ax in axs.flat:
# ax.set(xlabel='Year', ylabel='Utilization factor (%)')
for files in recycling_files_cost:
if '40209' in files:
state = globals()['%s_plants' % (files)].loc[globals()['%s_plants' % (files)]['location name'] == 'R D Morrow, Mississippi']
regex = re.findall('\w+_\w+_(\d{1,2})', files)[0]
axs[2, 1].plot(state['year'], state['total cost ($)'], label = fr'{regex}')
axs[2, 1].fill_between(state['year'], state['total cost ($)'], alpha=0.1)
#axs[2].legend(bbox_to_anchor=(1, 1.05), frameon=False)
axs[2, 1].set_title('R D Morrow, Mississippi')
axs[2, 1].margins(x=0, y=0)
axs[2, 1].set(xlabel="Year", ylabel="Total cost ($)")
fig, axs = plt.subplots(3, 2, figsize=(10,10),sharex=True)
fig.tight_layout(pad=1.5)
fig.suptitle("40209 Recycling plants - Capacity Sensitivity Analysis",fontsize=20)
fig.subplots_adjust(top=0.92)
for files in recycling_files_cap:
if 'NAI' in files:
state = globals()['%s_plants' % (files)].loc[globals()['%s_plants' % (files)]['location name'] == 'Navajo, Arizona']
regex = re.findall('\w+_\w+_(\d{1,2})', files)[0]
axs[0, 0].plot(state['year'], state['utilization factor (%)'], label = fr'{regex}')
axs[0, 0].fill_between(state['year'], state['utilization factor (%)'], alpha=0.1)
#axs[0].legend(bbox_to_anchor=(1, 1.05), frameon=False)
axs[0, 0].set_title('Navajo, Arizona')
axs[0, 0].margins(x=0, y=0)
# axs[0].xlabel('Year')
# axs[0].ylabel('Utilization factor (%)')
axs[0, 0].set(xlabel=" ", ylabel="Utilization factor (%)")
for files in recycling_files_cap:
if '40209' in files:
state = globals()['%s_plants' % (files)].loc[globals()['%s_plants' % (files)]['location name'] == 'Clinch River, Virginia']
regex = re.findall('\w+_\w+_(\d{1,2})', files)[0]
axs[1, 0].plot(state['year'], state['utilization factor (%)'], label = fr'{regex}')
axs[1, 0].fill_between(state['year'], state['utilization factor (%)'], alpha=0.1)
#axs[1, 0].legend(bbox_to_anchor=(1.1, 0.75), frameon=False)
axs[1, 0].set_title('Clinch River, Virginia')
axs[1, 0].margins(x=0, y=0)
axs[1, 0].set(xlabel=" ", ylabel="Utilization factor (%)")
# for ax in axs.flat:
# ax.set(xlabel='Year', ylabel='Utilization factor (%)')
for files in recycling_files_cap:
if '40209' in files:
state = globals()['%s_plants' % (files)].loc[globals()['%s_plants' % (files)]['location name'] == 'R D Morrow, Mississippi']
regex = re.findall('\w+_\w+_(\d{1,2})', files)[0]
axs[2, 0].plot(state['year'], state['utilization factor (%)'], label = fr'{regex}')
axs[2, 0].fill_between(state['year'], state['utilization factor (%)'], alpha=0.1)
#axs[2].legend(bbox_to_anchor=(1, 1.05), frameon=False)
axs[2, 0].set_title('R D Morrow, Mississippi')
axs[2, 0].margins(x=0, y=0)
axs[2, 0].set(xlabel="Year", ylabel="Utilization factor (%)")
for files in recycling_files_cap:
if '40209' in files:
state = globals()['%s_plants' % (files)].loc[globals()['%s_plants' % (files)]['location name'] == 'Navajo, Arizona']
regex = re.findall('\w+_\w+_(\d{1,2})', files)[0]
axs[0, 1].plot(state['year'], state['total cost ($)'], label = fr'{regex}')
axs[0, 1].fill_between(state['year'], state['total cost ($)'], alpha=0.1)
#axs[0].legend(bbox_to_anchor=(1, 1.05), frameon=False)
axs[0, 1].set_title('Navajo, Arizona')
axs[0, 1].margins(x=0, y=0)
# axs[0].xlabel('Year')
# axs[0].ylabel('Utilization factor (%)')
axs[0, 1].set(xlabel=" ", ylabel="Total cost ($)")
for files in recycling_files_cap:
if '40209' in files:
state = globals()['%s_plants' % (files)].loc[globals()['%s_plants' % (files)]['location name'] == 'Clinch River, Virginia']
regex = re.findall('\w+_\w+_(\d{1,2})', files)[0]
axs[1, 1].plot(state['year'], state['total cost ($)'], label = fr'{regex}')
axs[1, 1].fill_between(state['year'], state['total cost ($)'], alpha=0.1)
axs[1, 1].legend(bbox_to_anchor=(1.2, 0.75), frameon=False)
axs[1, 1].set_title('Clinch River, Virginia')
axs[1, 1].margins(x=0, y=0)
axs[1, 1].set(xlabel=" ", ylabel="Total cost ($)")
# for ax in axs.flat:
# ax.set(xlabel='Year', ylabel='Utilization factor (%)')
for files in recycling_files_cap:
if '40209' in files:
state = globals()['%s_plants' % (files)].loc[globals()['%s_plants' % (files)]['location name'] == 'R D Morrow, Mississippi']
regex = re.findall('\w+_\w+_(\d{1,2})', files)[0]
axs[2, 1].plot(state['year'], state['total cost ($)'], label = fr'{regex}')
axs[2, 1].fill_between(state['year'], state['total cost ($)'], alpha=0.1)
#axs[2].legend(bbox_to_anchor=(1, 1.05), frameon=False)
axs[2, 1].set_title('R D Morrow, Mississippi')
axs[2, 1].margins(x=0, y=0)
axs[2, 1].set(xlabel="Year", ylabel="Total cost ($)")
common_rec_NAICS = intersection( # Cost analysis
intersection(
intersection(
intersection(
Recycling_NAICS_1_plants['location name'].unique(),
Recycling_NAICS_05_plants['location name'].unique()),
Recycling_NAICS_2_plants['location name'].unique()),
Recycling_NAICS_5_plants['location name'].unique()),
Recycling_NAICS_10_plants['location name'].unique())
len(common_rec_NAICS)
52
common_rec_cap_NAICS = intersection( # Capacity analysis
intersection(
intersection(
intersection(
Recycling_cap_NAICS_1_plants['location name'].unique(),
Recycling_cap_NAICS_05_plants['location name'].unique()),
Recycling_cap_NAICS_2_plants['location name'].unique()),
Recycling_cap_NAICS_5_plants['location name'].unique()),
Recycling_cap_NAICS_10_plants['location name'].unique())
len(common_rec_cap_NAICS)
9
common_man_NAICS = intersection( # Cost analysis
intersection(
intersection(
Manufacturing_NAICS_0001_plants['location name'].unique(),
Manufacturing_NAICS_05_plants['location name'].unique()),
Manufacturing_NAICS_1_plants['location name'].unique()),
Manufacturing_NAICS_2_plants['location name'].unique())
len(common_man_NAICS)
116
common_man_cap_NAICS = intersection( # Capacity analysis
Manufacturing_cap_NAICS_1_plants['location name'].unique(),
Manufacturing_cap_NAICS_2_plants['location name'].unique())
len(common_man_cap_NAICS)
83
common_NAICS = intersection(
intersection(
intersection(
common_rec_NAICS, common_rec_cap_NAICS),
common_man_NAICS),
common_man_cap_NAICS)
len(common_NAICS)
9
common_NAICS
['Baldor Electric Co., AR', 'Columbia Block & Brick, MS', 'Gold Star Engraving & Awards, AZ', 'Standard Enterprises, Inc., VA', 'Prospect Machine, Inc., AZ', 'MMC Materials, Inc., MS', 'Boye Knives, AZ', 'Atlantic Fabrication & Boiler, VA', 'Bain Mfg. Co., Inc., MS']
The corresponding counties here are:
- Clarksville, Arizona
- Columbia, Missisipi
- Lake Havasu City, Arizona
- Charlottesville, Virginia
- Phoenix, Arizona
- Madison County, Missisipi
- Dolan Springs, Arizona
- Portsmouth, Virginia
- Grenada, Missisipi
Selected:
- Dolan Springs, Arizona or 'Boye Knives, AZ', close to Hualapai reservation.
- Grenada, Missisipi or 'Bain Mfg. Co., Inc., MS': Close to a highway,
- Charlottesville, Virginia or 'Standard Enterprises, Inc.': More remote,
os.getcwd()
'/Users/mmendez/Documents/Postdoc'